package com.wang.ssm.service;

import com.wang.ssm.mapper.QuestionMapper;
import com.wang.ssm.mapper.ScoreMapper;
import com.wang.ssm.mapper.StuanMapper;
import com.wang.ssm.pojo.Question;
import com.wang.ssm.pojo.Score;
import com.wang.ssm.pojo.Stuan;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author 王瑞杰
 * date 2023/10/28
 */
@Service
public class QuestionServiceImpl implements QuestionService{
    @Resource
    private QuestionMapper questionMapper;
    @Resource
    private ScoreMapper scoreMapper;
    @Resource
    private StuanMapper stuanMapper;
    @Override
    public List<Question> findAll() {
        return questionMapper.findAll();
    }

    @Override
    public boolean save(List<Question> question) {
        int size=question.size();
        int m=0;
        for (int i = 0; i < size; i++) {
            if (question.get(i).getQid() == null) {
                 m+=questionMapper.add(question.get(i));
            }else {
                m+= questionMapper.update(question.get(i));
            }
        }
        return m>=size;
    }

    @Override
    public boolean del(String[] arr) {
        return questionMapper.del(arr)>=1;
    }

    @Override
    public List<Score> findscore(String uid) {
        return scoreMapper.findAll(uid);
    }

    @Override
    public boolean addscore(Score score) {

        var date=new Date();
        score.setEtime(date);
        return scoreMapper.addscore(score)==1;
    }

    @Override
    public boolean addstuan(List<Stuan> stuan) {
        var date=new Date();
        int size=stuan.size();
                int m=0;
                for (int i = 0; i < size; i++) {
                    stuan.get(i).setEtime(date);
                         m+=stuanMapper.addstuan(stuan.get(i));
                }
        return m>=size;
    }

    @Override
    public List<Stuan> stuans(Stuan stuan) {
        return stuanMapper.stuans(stuan);
    }

}
